package com.fosss.band.utils;

import com.fosss.band.constant.MailConstant;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Component
public class SendMailUtil {
    //发件人
    @Value("${spring.mail.username}")
    private String from;

    @Resource
    private JavaMailSender javaMailSender;

    public void sendMail(String to, String code) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from + MailConstant.FROM_SUFFIX);
        message.setTo(to);
        message.setSubject(MailConstant.SUBJECT);
        message.setText(code);
        javaMailSender.send(message);
    }
}
